package com.corpgovernment.fuzzy;

import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.ctrip.corp.obt.generic.core.context.TenantContext;
import com.ctrip.corp.obt.generic.utils.EncryptUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import com.ctrip.corp.obt.shard.service.SyncHistoryDivideColumnService;
import com.ctrip.corp.obt.shard.service.SyncHistoryDivideColumnService.SyncHistoryDivideColumnRequest;
import com.ctrip.corp.obt.shard.service.SyncHistoryDivideColumnService.SyncHistoryDivideColumnResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author xukang zhang
 * @date 2024/1/7 13:58
 */
@RestController
@RequestMapping("/syncDivideColumn")
@Slf4j
public class SyncDivideColumnController {
    @Autowired
    private SyncHistoryDivideColumnService syncHistoryDivideColumnService;
    @Autowired
    @Qualifier(value = "defaultThreadPoolExecutor")
    private ThreadPoolExecutor basicThreadPoolExecutor;

    /**
    * 同步分词列
    *
    * @return
    */
    @PostMapping("/syncEmployeeInfo")
    public SyncHistoryDivideColumnResponse syncEmployeeInfo() {
        SyncHistoryDivideColumnRequest<MbOrgEmployeeInfo> mbOrgEmployeeInfoSyncHistoryDivideColumnRequest = new SyncHistoryDivideColumnRequest<>();
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setTenantId(TenantContext.getTenantId());
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setIdColumnName("id");
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setTableName("mb_org_employee_info");
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setIdGetter(mbOrgEmployeeInfo -> String.valueOf(mbOrgEmployeeInfo.getId()));
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setEntityClazz(MbOrgEmployeeInfo.class);
        mbOrgEmployeeInfoSyncHistoryDivideColumnRequest.setDecryptFunction(s -> EncryptUtils.sm4Decrypt(s, "1234567890123456"));
        basicThreadPoolExecutor.execute(() -> syncHistoryDivideColumnService.doSync(mbOrgEmployeeInfoSyncHistoryDivideColumnRequest));
        return SyncHistoryDivideColumnResponse.success();
    }
}
